<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>被测人管理</title>
<!-- 导入jquery核心类库 -->
<%@include file="../include/jqueryeasyui.jsp"%>

<script type="text/javascript">

$(function(){
	
	main();
	
});

	function main(){
		window.sizeRuleID = GetQueryString('sizeRuleID')  ;
		initDatagrid();
		initBtn();
		initxingWindow();
		initSaveBtn();
		initValidate();
		
	}
	
	function GetQueryString(name)
	{
	     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	     var r = window.location.search.substr(1).match(reg);
	     if(r!=null)return  unescape(r[2]); return null;
	}	
	
	function initDatagrid(){
		// 先将body隐藏，再显示，不会出现页面刷新效果
		$("body").css({visibility:"visible"});
		
		// 收派标准数据表格
		$('#grid').datagrid( {
			iconCls : 'icon-forward',
			fit : true,
			border : false,
			rownumbers : true,
			singleSelect:true,
			striped : true,
			toolbar : '#tb',
			url : "${pageContext.request.contextPath}/sizerule_cs/page.list.ashx",
			queryParams: window.sizeRuleID!=null?{ 'sizeRuleID': window.sizeRuleID}:new Object(),
			idField : 'id',
			columns : columns,
			pageList: [10,50,100,200],
			pagination:true,
			view:myview,
			emptyMsg:"<font size=5>暂无记录</font>"
			
		});
	}
	
	function initBtn(){
		
		$('#search').click(doSearch);
		$('#add').click(doAdd);
		$('#edit').click(doEdit);
		
	}
	
	function doAdd(){
		
		$('#xingWindow').form('clear');
		$('#xingWindow *').trigger('blur');// 离焦
		$('#xingWindow').window("open").window('setTitle', '套号规则');
		$('#sRCSID').val("-1");
		if(window.sizeRuleID!=null){
			$('#sizeRuleID').combobox('select', window.sizeRuleID);
			
		}
	}
	function doEdit(){
		var rowData = $('#grid').datagrid('getSelected');  
        
        if (rowData == null) {  
            $.messager.alert("提示", "请选择要修改的行！", "info");  
        } else{
        	$('#sizeRuleID').combobox('select', rowData.sizeRuleID);
        	$('#sRCSKey').val(rowData.sRCSKey);
        	$('#sRCSValue').val(rowData.sRCSValue);
        							    
        	$('#sRCSID').val(rowData.sRCSID);
	       
			

			// 弹出窗口
			  
			$("#xingWindow").window('open').window('setTitle', '修改套号规则名称');
        } 
	}
	
	
	function initxingWindow(){
		//初始化销售员窗口
		$('#xingWindow').window({
	           title: '名单详情',
	           width: 500,
	           modal: true,
	           shadow: true,
	           closed: true,
	           height: 500,
	           resizable:true,
	           
	           
	       });
	

	}

	
	function getQueryParams(queryParams) {  
		var searchcontent = $('#search_content').val();
	     queryParams.sRCSKey = searchcontent;  
	     return queryParams;  
	   
	 }  
	
	 //增加查询参数，重新加载表格  
    function reloadgrid() {  
  
        //查询参数直接添加在queryParams中      
        var queryParams = $('#grid').datagrid('options').queryParams;  
        getQueryParams(queryParams);  
        $('#grid').datagrid('options').queryParams = queryParams;  
        $("#grid").datagrid('load');  
    }  
	 
	function doSearch(){		
		reloadgrid();
	}
	

	// 定义列
	var columns = [ [  {
		field : 'v_srName',
		title : '所属套号规则',
		width : 150,	
	},{
		field : 'sRCSKey',
		title : '参数名',
		width : 100,	
	},{
		field : 'sRCSValue',
		title : '参数值',
		width : 100,	
	}, {
		field : 'sRCSID',
		title : '操作',
		width : 100,
		
		formatter:formatterId
	} ] ];
	
	
	 
	
	function formatterId(value,row,index) {
		return "<a onclick=doDel("+index+") href=#>删除</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
		
	}

	
	function formatterDate(value){
		if(value==''||null==value){
			return '';
		}
		var now = new Date(value);  
		var year=now.getYear()+1900; 
		var month=now.getMonth()+1; 
		var date=now.getDate(); 
		var hour=now.getHours(); 
		var minute=now.getMinutes();
		minute= (minute > 9) ? minute=minute : minute='0'+minute;
		//var second=now.getSeconds(); 
		return year+"-"+month+"-"+date+" "+hour+":"+minute; 
	}
	
	function doFuQuan(index){
	    $('#grid').datagrid('selectRow',index);// 关键在这里  
	    var row = $('#grid').datagrid('getSelected'); 

	    if(row){
			$.messager.alert("提示", "正在完善...", 'info');
		}
	}
	
	function formatterSex(value,row,index){
		if(row.sex==1){
			return "男";
		}else if(row.sex==2){
			return "女";
		}
	}


		
		

	
	
	
	var myview = $.extend({},$.fn.datagrid.defaults.view,{
		onAfterRender:function(target){
			$.fn.datagrid.defaults.view.onAfterRender.call(this,target);
			var opts = $(target).datagrid('options');
			var vc = $(target).datagrid('getPanel').children('div.datagrid-view');
			vc.children('div.datagrid-empty').remove();
			if (!$(target).datagrid('getRows').length){
				var d = $('<div class="datagrid-empty"></div>').html(opts.emptyMsg || 'no records').appendTo(vc);
				d.css({
					position:'absolute',
					left:0,
					top:50,
					width:'100%',
					textAlign:'center'
				});
			}
		}
	});

	function initSaveBtn(){
		
	
		$('#save').click(function(){
				// 校验
				if($('#sform').form('validate')){
					// 1 、获得form 数据
					var params = $('#sform').serialize();
					// 2、将数据发送给服务器 
					$.post("${pageContext.request.contextPath}/sizerule_cs/page.saveOrUpdate.ashx", params , function(data){
						if(data == "success"){
							// 成功
							$.messager.alert('消息','操作成功 ','info');
							// 关闭窗口
							$('#xingWindow').window('close');
							// 清除表单数据
							$('#xingWindow').form('clear');
							$('#xingWindow *').trigger('blur');// 离焦
							
							// 刷新表格数据 
							$('#grid').datagrid('reload');
						}else if(data == "conflict"){
							$.messager.alert('消息','同品类下号重复','info');
						}
						else{
							data =new String(data);
							if(data.charAt(0)=='<'){
								$.messager.alert('消息','没有权限 ','info');
							}else{
								$.messager.alert('消息','操作失败 ','info');
							}
							
						}
							
					});
				}
				
			});	
	
	}

	
		
</script>	
</head>
<body class="easyui-layout" >
	<div region="center"><table id="grid"></table></div>

		<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
		<a href="#" id="add" class="easyui-linkbutton" iconCls="icon-add" plain="true" >增加</a>
 		<a href="#" id="edit" class="easyui-linkbutton" iconCls="icon-edit" plain="true" >编辑</a>
	
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;所属套号规则: <input id="search_content" name="search_content" class="easyui-textbox" style="width:200px">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;参数名: <input id="search_content" name="search_content" class="easyui-textbox" style="width:200px">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="#"  id="search" class="easyui-linkbutton" iconCls="icon-search">搜索</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		
		</div>
	</div>
	
	<div class="easyui-window" title="参数详情" id="xingWindow" collapsible="false" minimizable="false" maximizable="false" style="top:50px;left:200px">
		<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
			<div class="datagrid-toolbar">
				<a id="save" icon="icon-save" href="#" class="easyui-linkbutton" plain="true" >保存</a>
			</div>
		</div>
		<div region="center" style="overflow:auto;padding:5px;" border="false">
			<form id="sform">
				<table class="table-edit" width="80%" align="center">
					<tr class="title">
						<td colspan="2">参数详情</td>
					</tr>
		

		
					<tr>
							<td>所属套号规则</td>
						<td>
						<input class="easyui-combobox"    editable="false",
									required="true"
									name="sizeRuleID"
									id="sizeRuleID"
									data-options="
											url:'${pageContext.request.contextPath}/sizeRuler/page.list_all.ashx?refreshcache=new Date().getTime()',
											method:'post',
											valueField:'sizeRuleID',
											textField:'sRName',
											panelHeight:'300',
											panelWidth:'300'
						"></td></tr><tr>
											<td>参数名</td>
						<td><input name="sRCSKey" id="sRCSKey" type="text" class="easyui-validatebox"  required="true"    /></td>

					</tr>
 					<input id="sRCSID" name="sRCSID" type="hidden" class="easyui-validatebox"/>
 					<tr>
						<td>参数值</td>
						<td><input name="sRCSValue" id="sRCSValue" type="text"  class="easyui-validatebox"  required="true"    /></td>
						
					</tr>
					
					
					
					</table>
			</form>
		</div>
	</div>
</body>

<script type="text/javascript">

function doDel(index){
    $('#grid').datagrid('selectRow',index);// 关键在这里  
    var row = $('#grid').datagrid('getSelected'); 
    if(row){ 

	     $.messager.confirm("操作提示", "确认删除 当前记录？", function (data) {  
	            if (data) {  
	            	$.post("${pageContext.request.contextPath}/sizerule_cs/page.del.ashx?sRCSID="+row.sRCSID,function(data){
		    			
		    			if(data == "success"){
		    				// 成功
		    				$.messager.alert('消息','操作成功 ','info');
		    				reloadgrid();
		    				
		    			
		    			}else{
		    					$.messager.alert('消息','<br>操作失败','info');
		    				
		    			}
		    				
		    		}); 
	            }  
	            else {  
	                 
	            }  
	        }); 


	}
}

function initValidate(){
	$.extend($.fn.validatebox.defaults.rules, {   
	    //验证汉字   
	    CHS: {   
	        validator: function (value) {   
	            return /^[\u0391-\uFFE5]+$/.test(value);   
	        },   
	        message: '只能输入汉字'  
	    },   
	    //移动手机号码验证   
	    mobile: {//value值为文本框中的值   
	        validator: function (value) {   
	            var reg = /^1[3|4|5|7|8|9]\d{9}$/;   
	            return reg.test(value);   
	        },   
	        message: '输入手机号码格式不准确.'  
	    },   
	    //国内邮编验证   
	    zipcode: {   
	        validator: function (value) {   
	            var reg = /^[1-9]\d{5}$/;   
	            return reg.test(value);   
	        },   
	        message: '邮编必须是非0开始的6位数字.'  
	    },   
	    //用户账号验证(只能包括 _ 数字 字母)    
	    account: {//param的值为[]中值   
	        validator: function (value, param) {   
	            if (value.length < param[0] || value.length > param[1]) {   
	                $.fn.validatebox.defaults.rules.account.message = '用户名长度必须在' + param[0] + '至' + param[1] + '范围';   
	                return false;   
	            } else {   
	                if (!/^[\w]+$/.test(value)) {   
	                    $.fn.validatebox.defaults.rules.account.message = '用户名只能数字、字母、下划线组成.';   
	                    return false;   
	                } else {   
	                    return true;   
	                }   
	            }   
	        }, message: ''  
	    },
	    hk: {   
	        validator: function (value) {   
	            var reg = /\d\d\d,\d\d\d/;   
	            return reg.test(value);   
	        },   
	        message: '请输入正确格式    155,160'  
	    },
	    hao: {   
	        validator: function (value) {   
	            var reg = /\d\d\d/;   
	            return reg.test(value);   
	        },   
	        message: '请输入正确格式    155'  
	    }
	})
}

</script>
</html>